import { POST } from "@/api";
import { config } from "@/config";
import { VagueOject } from "@/types/common";
import { CarType } from "@/types/res/car";

export const addCar = async (data: VagueOject = {}, header: VagueOject = {}): Promise<void> => {
    return await POST<void>({
        url: config.apiList.addCar,
        data,
        header
    })
}

export const submitCar = async (data: VagueOject = {}, header: VagueOject = {}): Promise<void> => {
    return await POST<void>({
        url: config.apiList.submitCar,
        data,
        header
    })
}

export const updateCarNum = async (data: VagueOject = {}, header: VagueOject = {}): Promise<void> => {
    return await POST<void>({
        url: config.apiList.updateCarNum,
        data,
        header
    })
}

export const getCarList = async (data: VagueOject = {}, header: VagueOject = {}): Promise<CarType[]> => {
    let res = await POST<CarType[]>({
        url: config.apiList.getCarList,
        data,
        header
    })

    if (Array.isArray(res)) {
        res.forEach(v => {
            v.wares_masterimg = JSON.parse(<string>v.wares_masterimg)
        })
    } else {
        res = []
    }
    return res;
}

export const checkCar = async (data: VagueOject = {}, header: VagueOject = {}): Promise<{ isAddCar: boolean }> => {
    return await POST<{ isAddCar: boolean }>({
        url: config.apiList.checkCar,
        data,
        header
    })
}

export const deleteCar = async (data: VagueOject = {}, header: VagueOject = {}): Promise<any> => {
    return await POST<any>({
        url: config.apiList.deleteCar,
        data,
        header
    })
}


